<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class comment extends CI_Controller {
	
	//-เพิ่มข้อมูลคอมเมนต์-//
	public function Addcomment()
	{
		if($this->input->post("Submit")!= null)
		{
			$config['upload_path']="images/approve/";
			$config['allowed_types']="jpg|gif|png|doc|docx";
			$config['max_size']=100000; //kb
			$config['max_height']=1024; //px
			$config['max_width']=1024; //px

			$this->load->library("upload");
			$this->upload->initialize($config);
			
			if($this->upload->do_upload("picture"))
			{
				$data=$this->upload->data();
				rename($data['full_path'],$data['file_path'].date("YmdHis").$data['file_ext']);
				$image = date("YmdHis");
				$file = $image.$data['file_ext'];
			$inputdata = array
				(
					"user_id"=>$this->input->post("user_id"),
					"t_id"=>$this->input->post("t_id"),
					"comment"=>$this->input->post("comment"),
					"file"=>$file,
					"date"=>$this->input->post("date")
				);
				$this->comment_model->add_comment($inputdata);
			}
			else
			{
			$inputdata = array
				(
					"user_id"=>$this->input->post("user_id"),
					"t_id"=>$this->input->post("t_id"),
					"comment"=>$this->input->post("comment"),
					"date"=>$this->input->post("date")
				);
				//print_r($file);
				$this->comment_model->add_comment($inputdata);
			}
		}
			$t_id = $this->uri->segment(3);
			$data['rs']=$this->comment_model->detail_comment($t_id);
			$this->load->view("comment/Add-comment",$data);
	}
	//-จบ-//

}
 